# For VS2022 and Xcode 12+ support.
cmake_minimum_required(VERSION 3.21)

# Only generate Debug and Release configuration types.
set(CMAKE_CONFIGURATION_TYPES Debug Release)

# Project name.
project(fio66_player)

set(CMAKE_CXX_STANDARD 20)

# Use folders in the resulting project files.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Include ExternalProject module to download and build glog
include(ExternalProject)

# Set logger directory paths
set(LOGGER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/logger")
set(GLOG_INSTALL_DIR "${LOGGER_DIR}")
set(GLOG_INCLUDE_DIR "${GLOG_INSTALL_DIR}/include")
set(GLOG_LIB_DIR "${GLOG_INSTALL_DIR}/lib")

# Download, build and install glog as static library
ExternalProject_Add(
    glog
    GIT_REPOSITORY https://github.com/google/glog.git
    GIT_TAG v0.6.0
    GIT_CONFIG http.sslVerify=false
    CMAKE_ARGS
        -DCMAKE_INSTALL_PREFIX=${GLOG_INSTALL_DIR}
        -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
        -DWITH_GFLAGS=OFF
        -DBUILD_TESTING=OFF
        -DBUILD_SHARED_LIBS=OFF
        -DCMAKE_CXX_STANDARD=20
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5
    PREFIX ${CMAKE_CURRENT_BINARY_DIR}/glog
    UPDATE_COMMAND ""
    INSTALL_COMMAND 
        ${CMAKE_COMMAND} --build <BINARY_DIR> --target install
)

set(CEF_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/cef")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake")


set(FFMPEG_ROOT "${CMAKE_SOURCE_DIR}/ffmpeg" CACHE PATH "Path to ffmpeg root" FORCE)
set(FFMPEG_INCLUDE_DIR "${FFMPEG_ROOT}/include" CACHE PATH "Path to ffmpeg include" FORCE)
set(FFMPEG_LIB_DIR "${FFMPEG_ROOT}/lib/x64" CACHE PATH "Path to ffmpeg lib" FORCE)

find_package(CEF REQUIRED)

include_directories(${PROJECT_SOURCE_DIR} ${GLOG_INCLUDE_DIR})

# Create a custom target for the logger
add_library(logger INTERFACE)
add_dependencies(logger glog)

add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper)

add_subdirectory(audio_player)
add_subdirectory(ffmpeg_wrapper)
# Display configuration settings.
PRINT_CEF_CONFIG()

